package com.clas.liu.myapplication.presenter.impl;

import android.os.Handler;
import android.os.Message;

import com.clas.liu.myapplication.model.entity.info.InfoRoot;
import com.clas.liu.myapplication.model.event.CategoryEvent;
import com.clas.liu.myapplication.model.impl.CategoryModel;
import com.clas.liu.myapplication.presenter.i.ICategoryPresenter;
import com.clas.liu.myapplication.view.activity.impl.CategoryActivity;

/**
 * Created by liu on 2019/5/8.
 */

public class CategoryPresenter extends BasePresenter<CategoryActivity, CategoryModel> implements ICategoryPresenter {

    public CategoryPresenter(CategoryActivity view) {
        super(view);
    }

    @Override
    public void getInfo(int category, int page_no, int page_size) {
        mModel.getInfo(category,page_no,page_size);
    }

    @Override
    protected CategoryModel getModel(Handler handler) {
        return new CategoryModel(handler);
    }

    @Override
    protected void eventReceive(Message msg) {
        switch (msg.what) {
            case CategoryEvent.GET_CATEGORY_INFO_OK:
                InfoRoot infoRoot = ((CategoryEvent)msg.obj).getRoot();
                mView.InfoReturn(infoRoot.getCode(),infoRoot.getData());
                break;
            case CategoryEvent.GET_CATEGORY_INFO_FAIL:
                mView.failBecauseNetReturn(msg.what);
                break;
        }
    }
}
